package com.gaotong.science.config;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.gaotong.science.entity.HightTech;
import com.gaotong.science.entity.HightTechzone;
import com.gaotong.science.service.HightService;
import com.gaotong.science.service.HightTechzoneService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.UUID;

@Component
public class HightExcelListener extends AnalysisEventListener<HightTech> {

    public HightTechzoneService hightTechzoneService;
    public HightExcelListener(){}
    public HightExcelListener(HightTechzoneService hightTechzoneService) {
        this.hightTechzoneService=hightTechzoneService;
    }
    @Override
    public void invoke(HightTech hightTech, AnalysisContext analysisContext) {
        System.out.println(hightTech);
        HightTechzone hightTechzone = new HightTechzone();
        BeanUtils.copyProperties(hightTech,hightTechzone);
//        String uuid = UUID.randomUUID().toString().replace("-", "");
////        System.out.println(uuid);
//        uuid = uuid.substring(0, 6);
//        hightTechzone.setId(uuid);
        hightTechzoneService.save(hightTechzone);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }


    @Override
    public void invokeHead(Map map, AnalysisContext analysisContext) {

    }
}
